// 封装localstorage相关的读取操作
const INFO_KEY = 'shopping_info'
const HISTORY_KEY = 'shopping_history'

// 1. token的持久化
// 获取个人信息，为空时返回空对象而不是null
export const getInfo = () => {
  const result = localStorage.getItem(INFO_KEY)
  return result ? JSON.parse(result) : {}
}
// 设置个人信息
export const setInfo = (info) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(info))
}
// 删除个人信息
export const removeInfo = () => {
  localStorage.removeItem(INFO_KEY)
}

// 2. 搜索历史持久化
export const getHistoryList = () => {
  const result = localStorage.getItem(HISTORY_KEY)
  return result ? JSON.parse(result) : []
}

export const setHistoryList = (HsitoryList) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(HsitoryList))
}

export const removeHistoryList = () => {
  localStorage.removeItem(HISTORY_KEY)
}
